<?php
/**
 * ModifyShift Function
 *
 * Modify an existing shift
 *
 * @author Max Sibbald <maxsibbald@gmail.com>
 */
include_once 'UTerrorcode.php';
include_once 'UTcheckAuth.php';
include_once 'UTDbglobal.php';
/**
 * @param $authUser string
 * @param $authUserPass string
 * @param $roleID string
 * @param $dateID string
 * @param $empID string
 * @param $fieldToModify string
 * @param $newValue
 * @return array
 */
function modifyShift($authUser, $authUserPass, $roleID, $dateID, $empID, $fieldToModify, $newValue)
{
	global $dbaddress;
    global $dbuser;
    global $dbpassword;
    global $dbdatabasename;
	
      if (checkAuthentication($authUser, $authUserPass) != true){
      	return array(ErrorCode::authFailRead);	
      }

      $conn=mysql_connect($dbaddress,$dbuser,$dbpassword,$dbdatabasename);
      if(!$conn)
      {
            die('Could not connect: ' . mysql_error());
            return array(ErrorCode::sysError);
      }

      if ($fieldToModify == 'empID'){
            $sql = "UPDATE RoleDate SET empID = '$newValue' WHERE roleID='$roleID' AND dateID='$dateID' AND empID='$empID'";
      } else if ($fieldToModify == "dateID"){
            $sql = "UPDATE RoleDate SET dateID = '$newValue' WHERE roleID='$roleID' AND dateID='$dateID' AND empID='$empID'";
      } else if ($fieldToModify == "roleID"){
            $sql = "UPDATE RoleDate SET roleID = '$newValue' WHERE roleID='$roleID' AND dateID='$dateID' AND empID='$empID'";
      } else if ($fieldToModify == "shiftStatus"){
            $sql =  "UPDATE RoleDate SET shiftStatus = '$newValue' WHERE roleID='$roleID' AND dateID='$dateID' AND empID='$empID'";
      } else if ($fieldToModify == "startTime"){
            $sql = "UPDATE RoleDate SET startTime = '$newValue' WHERE roleID='$roleID' AND dateID='$dateID' AND empID='$empID'";
      } else if ($fieldToModify == "endTime"){
            $sql = "UPDATE RoleDate SET endTime = '$newValue' WHERE roleID='$roleID' AND dateID='$dateID' AND empID='$empID'";
      } else {
      	return array(ErrorCode::failUpdate);
      }

      if (mysql_query($conn, $sql)){
            mysql_close($conn);
            return array(ErrorCode::successUpdate);
      } else {
            mysql_close($conn);
            return array(ErrorCode::failDelete);
      }
}

?>